package com.xiaoshuidi.cloud.module.member.util;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.img.ImgUtil;
import cn.hutool.extra.qrcode.QrCodeUtil;

import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;

public class QrCodeGeneratorUtil {
    public static String generateQrCode(String content, int width, int height) {
        // 生成二维码图片
        BufferedImage image = QrCodeUtil.generate(content, width, height);
        // 将二维码图片转换成Base64编码的字符串
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ImgUtil.writePng(image, outputStream);
        return "data:image/png;base64," + Base64.encode(outputStream.toByteArray());
    }
}
